import requests

cookie = '''Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6Mjg3NjQyOSwidXNlcm5hbWUiOiJkdS0tZHUiLCJidWNrZXQiOiJkdS0tZHUiLCJzdGF0ZSI6IjBmMDgzZWI5ODhhZWI0ZWI5ZWIwZDY2Y2IwMTA3Nzc4Iiwic3RhdHVzIjoxLCJpYXQiOjE1ODYyNTM5NTF9.TXgeoao4z_l7EwhcWV_gsVO9Bydp-gjBO2OETuwHdRo'''
token = 'Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6Mjg3NjQyOSwidXNlcm5hbWUiOiJkdS0tZHUiLCJidWNrZXQiOiJkdS0tZHUiLCJzdGF0ZSI6IjBmMDgzZWI5ODhhZWI0ZWI5ZWIwZDY2Y2IwMTA3Nzc4Iiwic3RhdHVzIjoxLCJpYXQiOjE1ODYyNzM3MzF9.mlHTZZofnfQw4t9ujuWDhiXbEg8LASeuic8ZtA3CLjM'

headers = {
    'Accept': '*/*',
    'Accept-Encoding': 'gzip, deflate, br',
    'Accept-Language': 'zh-CN,zh;q=0.9',
    'Authorization': token,

    # 'Content-Type': 'multipart/form-data; boundary=----WebKitFormBoundaryDQZR88GhcwFHZ3jg',
    'Cookie': cookie,

    'Host': 'x.yupoo.com',
    'Origin': 'https://x.yupoo.com',
    'Referer': 'https://x.yupoo.com/gallery/pick',
    'Sec-Fetch-Mode': 'cors',
    'Sec-Fetch-Site': 'same-origin',
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.79 Safari/537.36',
}

api_url = 'https://x.yupoo.com/api/photos'

def new_img_url(img_source_url, name=None, content_type='image/jpeg'):
    name = name or img_source_url
    img = requests.get(img_source_url)
    if img.status_code == 200:
        img = img.content
        content_type = 'image/png' if img_source_url[-3:] == 'png' else content_type
        files = {'photo': (name, img, content_type)}

        res = requests.post(api_url, data={'albumId': 79402271, 'name': name, },
                            files=files, headers=headers)
        return res.json() if res.status_code == 200 else -1, res.text

